package com.kc.business.service.impl;

import com.kc.business.domain.BizCreation;
import com.kc.business.domain.BizSiteVideo;
import com.kc.business.domain.BizUserCreation;
import com.kc.business.mapper.BizUserCreationMapper;
import com.kc.business.service.IBizCreationService;
import com.kc.business.service.IBizSiteVideoService;
import com.kc.business.service.IBizUserCreationService;
import com.kc.common.utils.DateUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
/**
 *用户创作模块业务实现
 */
@Service
public class BizUserCreationServiceImpl implements IBizUserCreationService {
    @Autowired
    private BizUserCreationMapper bizUserCreationMapper;
    //旅知模块service
    @Autowired
    private IBizCreationService iBizCreationService;
    //景点视频
    @Autowired
    private IBizSiteVideoService iBizSiteVideoService;

    /**
     * 获取创作列表
     * @return
     */
    @Override
    public List<BizUserCreation> getList() {
            List<BizUserCreation> userCreationList = bizUserCreationMapper.getList();
            return userCreationList;
    }

    /**
     * 审核拒绝
     * @param id  id
     * @param refuseInfo  拒绝原因
     * @return
     */
    @Override
    public Integer examineRefuse(String id, String refuseInfo) {
        return bizUserCreationMapper.examineRefuse(id,refuseInfo);
    }

    /**
     * 审核通过
     * @param id
     * @return
     */
    @Override
    @Transactional
    public Integer examinePass(String id) {
        BizUserCreation bizUserCreation = this.getInfo(id);
        if(!bizUserCreation.getStatus().equals("0")){
            return 0;
        }
        if(bizUserCreation.getType().equals("0")){
            //景点视频
            BizSiteVideo bizSiteVideo = new BizSiteVideo();
            BeanUtils.copyProperties(bizUserCreation, bizSiteVideo);
            if(bizSiteVideo.getIsOfficial() == null){
                bizSiteVideo.setIsOfficial(0);
            }
            bizSiteVideo.setStatus(1);
            bizSiteVideo.setSiteId(bizSiteVideo.getThemeId());
            bizSiteVideo.setVideoImg(bizSiteVideo.getImage());
            bizSiteVideo.setContent(bizSiteVideo.getSynopsis());
            bizSiteVideo.setVideo(bizSiteVideo.getVideoUrl());
            bizSiteVideo.setCreateTime(DateUtils.parseDate(bizSiteVideo.getCreationTime()));
            Integer linkId = iBizSiteVideoService.insertDate(bizSiteVideo);
            bizUserCreation.setLinkId(linkId);
        }else {
            //数据写入旅知模块表
            BizCreation bizCreation = new BizCreation();
            BeanUtils.copyProperties(bizUserCreation, bizCreation);
            if(bizCreation.getIsOfficial() == null){
                bizCreation.setIsOfficial(0);
            }
            bizCreation.setStatus("1");
            bizCreation.setScenicId(bizUserCreation.getThemeId());
            Integer linkId = iBizCreationService.insertData(bizCreation);
            bizUserCreation.setLinkId(linkId);
        }
        bizUserCreationMapper.updateByPrimaryKey(bizUserCreation);
        bizUserCreationMapper.examinePass(id);
        return 1;
    }

    /**
     * 获取创作详情
     * @param id
     * @return
     */
    @Override
    public BizUserCreation getInfo(String id) {
        return bizUserCreationMapper.getInfo(id);
    }
}
